/*  1:   */package com.mrd.dolphin.net.mina.codec;
/*  2:   */
/*  5:   */

import com.mrd.packet.PbPacket;

import java.nio.ByteBuffer;
/*  6:   */import org.apache.mina.core.buffer.IoBuffer;
/*  7:   */import org.apache.mina.core.session.IoSession;
/*  8:   */import org.apache.mina.filter.codec.ProtocolEncoder;
/*  9:   */import org.apache.mina.filter.codec.ProtocolEncoderOutput;
/* 10:   */import org.slf4j.Logger;
/* 11:   */import org.slf4j.LoggerFactory;
/* 12:   */
/* 23:   */public class PbEncoder
/* 24:   */  implements ProtocolEncoder
/* 25:   */{
/* 26:26 */  private static final Logger log = LoggerFactory.getLogger(PbEncoder.class);
/* 27:   */  
/* 28:   */  public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception
/* 29:   */  {
/* 30:   */    try {
					System.out.println("message str:"+message.toString());
/* 31:31 */      PbPacket packet = (PbPacket)message;
				System.out.println("step 2:");
/* 32:32 */  
/* 33:33 */      IoBuffer buffer = null;
				System.out.println("step 3:");
/* 34:34 */      byte[] body = new byte[0];
/* 35:35 */      if (packet.getData() != null) {
/* 36:36 */        body = packet.getData();
/* 37:37 */        int length = 24 + body.length;
/* 38:38 */        buffer = IoBuffer.allocate(length).setAutoExpand(true);
/* 39:39 */        buffer.putInt(body.length);
/* 40:40 */        buffer.putInt(packet.getPacketId());
/* 41:41 */        buffer.putLong(packet.getStamp());
/* 42:42 */        buffer.putInt(packet.getRetCode());
/* 43:43 */        buffer.putInt(packet.getFlag());
/* 44:44 */        buffer.put(body);
/* 45:   */      } else {
/* 46:46 */        buffer = IoBuffer.allocate(24).setAutoExpand(true);
/* 47:47 */        buffer.putInt(0);
/* 48:48 */        buffer.putInt(packet.getPacketId());
/* 49:49 */        buffer.putLong(packet.getStamp());
/* 50:50 */        buffer.putInt(packet.getRetCode());
/* 51:51 */        buffer.putInt(packet.getFlag());
/* 52:   */      }
/* 53:53 */      buffer.flip();
/* 54:54 */      out.write(buffer);
/* 55:55 */      out.flush();
/* 56:   */      
/* 57
/* 58:   */    }
/* 59:   */    catch (Exception e) {
/* 60:60 */
/* 61:61 */      e.printStackTrace();
/* 62:   */    }
/* 63:   */  }
/* 64:   */  
/* 65:   */  public void dispose(IoSession session)
/* 66:   */    throws Exception
/* 67:   */  {}
/* 68:   */}


/* Location:           D:\MMOServer\MMOServer\lib\mrd-framework\
 * Qualified Name:     com.mrd.dolphin.net.mina.codec.PbEncoder
 * JD-Core Version:    0.7.0-SNAPSHOT-20130630
 */